package web_report

import (
	"math/rand"
	"sort"
)

type BankManagementStudentWebReport struct {
	*DefaultWebReport
}

func (b *BankManagementStudentWebReport) GetPosLabels() []LabelValue {
	chartsData := make([]LabelValue, 0)
	for _, pos := range b.evaluateResp.PosWordScore.General {
		score := 60 + int(pos[1].(float64)*100*25/100)
		score += rand.Intn(10) + 1
		chartsData = append(chartsData, LabelValue{
			Label: pos[0].(string),
			Value: score,
		})
	}

	for _, pos := range b.evaluateResp.PosWordScore.Profession {
		score := 60 + int(pos[1].(float64)*100*25/100)
		score += rand.Intn(10) + 1
		chartsData = append(chartsData, LabelValue{
			Label: pos[0].(string),
			Value: score,
		})
	}
	sort.Slice(chartsData, func(i, j int) bool {
		return chartsData[i].Value > chartsData[j].Value
	})
	if len(chartsData) > 5 {
		return chartsData[:5]
	}
	return chartsData
}

func (b *BankManagementStudentWebReport) GetNegLabels() []LabelValue {
	chartsData := make([]LabelValue, 0)
	for _, neg := range b.evaluateResp.NegScoreDict.Profession {
		score := int(neg[1].(float64) * 100 * 60 / 100)
		if score > 0 {
			chartsData = append(chartsData, LabelValue{
				Label: neg[0].(string),
				Value: score,
			})
		}
	}
	for _, neg := range b.evaluateResp.NegScoreDict.General {
		score := int(neg[1].(float64) * 100 * 30 / 100)
		if score > 0 {
			chartsData = append(chartsData, LabelValue{
				Label: neg[0].(string),
				Value: score,
			})
		}
	}
	sort.Slice(chartsData, func(i, j int) bool {
		return chartsData[i].Value > chartsData[j].Value
	})
	if len(chartsData) > 5 {
		return chartsData[:5]
	}
	return chartsData
}

func (b *BankManagementStudentWebReport) GetGeneralData() *ScoreChart {
	chartsData := make([]LabelValue, 0)
	chartsData = append(chartsData, b.GetPosLabels()...)
	chartsData = append(chartsData, b.GetNegLabels()...)
	return &ScoreChart{
		Score:     int(b.evaluateResp.LabelScore.General * 100),
		ChartData: chartsData,
	}
}
